import { IPineSeries, IPineStudyResult, LibraryPineStudy, RawStudyMetaInfoId } from "./charting_library/charting_library";

let point = new Array(38).fill(0).map((i, index) => {
    return {
        id: `plot_${index}`,
        type: index % 2 ? `colorer` : `line`,
        target: index % 2 ? `plot_${index - 1}` : `plot_${index}`,
        palette: "paletteId1",
        editable: true
    };
});
point[0].target = "plot_0";
point[1].palette = "paletteId4";
point[35].palette = "paletteId2";
point[37].palette = "paletteId3";
console.log(point, "pointpoint");
const shage = (PineJS, tradingSymbol) => ({
    name: "CVLINE",
    metainfo: {
        _metainfoVersion: 51,
        id: "CVLINE@tv-basicstudies-1" as RawStudyMetaInfoId,
        description: "CVLINE",
        shortDescription: "CVLINE",
        is_price_study: true,
        isCustomIndicator: true,
        plots: point,
        palettes: {
            paletteId1: {
                colors: {
                    0: {
                        name: "First color122"
                    },
                    1: {
                        name: "Second color233"
                    },
                    2: {
                        name: "tecond color344"
                    }
                }
            },
            paletteId2: {
                colors: {
                    0: {
                        name: "First color122"
                    },
                    1: {
                        name: "Second color233"
                    },
                    2: {
                        name: "tecond color344"
                    }
                }
            },
            paletteId3: {
                colors: {
                    0: {
                        name: "First color122"
                    },
                    1: {
                        name: "Second color233"
                    },
                    2: {
                        name: "tecond color344"
                    }
                }
            },
            paletteId4: {
                colors: {
                    0: {
                        name: "First color122"
                    },
                    1: {
                        name: "Second color233"
                    },
                    2: {
                        name: "tecond color344"
                    }
                }
            }
        },
        defaults: {
            palettes: {
                paletteId1: {
                    colors: {
                        0: {
                            color: "#0f0",
                            width: 1,
                            style: 0
                        },
                        1: {
                            color: "#f00",
                            width: 1,
                            style: 0
                        },
                        2: {
                            color: "rgba(255,0,0,0)",
                            width: 1,
                            style: 0
                        }
                    }
                },
                paletteId2: {
                    colors: {
                        0: {
                            color: "#0f0",
                            width: 3,
                            style: 0
                        },
                        1: {
                            color: "#f00",
                            width: 3,
                            style: 0
                        },
                        2: {
                            color: "rgba(255,0,0,0)",
                            width: 3,
                            style: 0
                        }
                    }
                },
                paletteId3: {
                    colors: {
                        0: {
                            color: "#FCC235",
                            width: 4,
                            style: 0
                        },
                        1: {
                            color: "#FCC235",
                            width: 4,
                            style: 0
                        },
                        2: {
                            color: "#FCC235",
                            width: 4,
                            style: 0
                        }
                    }
                },
                paletteId4: {
                    colors: {
                        0: {
                            color: "#0f0",
                            width: 3,
                            style: 0
                        },
                        1: {
                            color: "#f00",
                            width: 3,
                            style: 0
                        },
                        2: {
                            color: "rgba(255,0,0,0)",
                            width: 3,
                            style: 0
                        }
                    }
                }
            },
            styles: {
                plot_0: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_2: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_4: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_6: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_8: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_10: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_12: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_14: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_16: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_18: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_20: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_22: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_24: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_26: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_28: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_30: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_32: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_34: {
                    // 绘制透明度，百分比。
                    transparency: 0
                },
                plot_36: {
                    // 绘制透明度，百分比。
                    transparency: 0
                }
            },
            precision: 4,
            inputs: {}
        },
        styles: {
            plot_0: {
                title: "Equity value",
                histogramBase: 0,
                editable: true
            },
            plot_2: {
                title: "Equity value22",
                histogramBase: 0,
                editable: true
            },
            plot_3: {
                title: "Equity value33",
                histogramBase: 0,
                editable: true
            }
        },
        inputs: [],
        format: {
            type: "price",
            precision: 4
        }
    },
    constructor: function (this: LibraryPineStudy<IPineStudyResult>) {
        this.init = function (context, inputCallback) {
            this._context = context;
            this._input = inputCallback;

            // 定义要绘制的商品。
            // 商品应该是一个字符串。
            // 您可以使用PineJS.Std.ticker（this._context）获取所选商品的代码。
            // 例,
            //    var symbol = "AAPL";
            //    var symbol = "#EQUITY";
            //    var symbol = PineJS.Std.ticker(this._context) + "#TEST";
            let k_type = tradingSymbol || "ETH/USDT";
            var symbol = k_type;
            this._context.new_sym(symbol, PineJS.Std.period(this._context), PineJS.Std.period(this._context));
        };
        this.main = function (context, inputCallback) {
            this._context = context;
            this._input = inputCallback;

            this._context.select_sym(1);
            let close = PineJS.Std.close(this._context);
            let barData = window.WTTbarData;
            let params = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 144];
            let arr = window.WTTLineData;
            // let item1 = barData.find(i=>i.startTime==this._context.symbol.time)
            // let ii = barData.indexOf(item1);
            let ii = barData.findIndex(i => i.startTime == this._context.symbol.time);
            if (ii >= 0) {
                return arr[ii];
            }
        };
    }
});

export { shage };
